<template>
    <div class="navigation">
       <swiper :options="swiperOption">
         <swiper-slide v-for="(page ,index) in pages" :key="index">
          <div class="nav-item" v-for="item in page" :key="item.id">
              <a href="#">
                  <div class="nav-img" v-html=item.img> </div>
                  <div class="nav-text">{{item.name}}</div>
              </a>
          </div>
         </swiper-slide>
          <div class="swiper-pagination swiper-log" slot="pagination"></div>
       </swiper>
    </div>
</template>
<script>
import axios from 'axios'
export default {
  name: 'HomeNavigation',
  data () {
    return {
      navList: [],
      swiperOption: {
        pagination: {
          el: '.swiper-pagination'
        }
      }
    }
  },
  created () {
    axios({
      method: 'get',
      url: 'http://192.168.1.30:9090/api/getindexmenu'
    }).then(res => {
      // console.log(res.data)
      this.navList = res.data.result
    })
  },
  computed: {
    pages () {
      // 总页数
      const pages = []
      this.navList.forEach((item, index) => {
        // 当前元素的展示在第几页
        const page = Math.floor(index / 8)

        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.nav-img img{
    height: 1.2rem;
    width: 1.2rem;
}
/deep/.navigation .swiper-pagination{
color: red;
}
/deep/.swiper-log swiper-pagination-bullets{
  width: 1rem /* 50/50 */;
  height: .4rem /* 20/50 */;
}

.navigation{
  // height: 300px;
  width: 100%;
  background-color:#F6F6F6;
  .swiper-pagination{
     position: static;
  }
 .nav-item{
   width: 25%;
   float: left;
   text-align: center;
   padding-top: .1rem /* 5/50 */;
   .swiper-log{
     padding-top: .1rem /* 5/50 */;
   }
   a{
     display: block;
     color: #000;
     .nav-text{
        text-align: center;
        font-size: .18rem;
        line-height: .5rem;
        color: #000;
          }
   }
 }
}

</style>
